package com.sgb.kjwl.view.ui.activity.transport.driver.goods;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.Html;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.tabs.TabLayout;
import com.sgb.capital.view.ui.activity.OpenAccountFirstActivity;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityFreightDetailBiddingBinding;
import com.sgb.kjwl.model.entity.CarInfo;
import com.sgb.kjwl.model.entity.self.GoodsSourceDetail;
import com.sgb.kjwl.model.entity.self.UserAccount;
import com.sgb.kjwl.model.entity.transport.GoodsSourcePlace;
import com.sgb.kjwl.utils.CargoConstant;
import com.sgb.kjwl.utils.DefaultUtil;
import com.sgb.kjwl.utils.EntityConversion;
import com.sgb.kjwl.utils.LogisticsPermissionHelper;
import com.sgb.kjwl.utils.NumberUtil;
import com.swgk.core.util.UserOperating;
import com.swgk.core.event.EventConstant;
import com.sgb.kjwl.view.event.LogisticsEvent;
import com.sgb.kjwl.view.ui.activity.manage.WebsiteInfoActivity;
import com.sgb.kjwl.view.ui.activity.self.AddCarInfoActivity;
import com.sgb.kjwl.view.ui.activity.self.logistics.OfferOwnerListActivity;
import com.sgb.kjwl.view.ui.activity.self.logistics.QuotedOwnerActivity;
import com.sgb.kjwl.view.ui.activity.self.logistics.QuotedThirdActivity;
import com.sgb.kjwl.view.ui.activity.self.logistics.ReleaseCargoActivity;
import com.sgb.kjwl.view.ui.activity.self.userInfo.VerificationCodeLoginActivity;
import com.sgb.kjwl.view.ui.activity.transport.CargoQuotationActivity;
import com.sgb.kjwl.view.ui.activity.transport.HandleAdressActivity;
import com.sgb.kjwl.view.ui.activity.transport.InquireByLetterActvity;
import com.sgb.kjwl.view.ui.activity.transport.PayBiddingOrderActivity;
import com.sgb.kjwl.view.ui.activity.transport.ShareLogisticsActivity;
import com.sgb.kjwl.view.ui.adapter.transport.FreightPrjDetailAdapter;
import com.sgb.kjwl.view.widget.RoundImageView;
import com.sgb.link.entity.LogisticsFlowLog;
import com.sgb.link.utils.LogisticsLogUtils;
import com.swgk.core.base.aroute.AppRouteConstant;
import com.swgk.core.dialog.RoundDialog;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.SharedPreferenceUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @Author : 熊丽
 * @date :2021/7/15 0015$ 14:52$
 * @Description ://竞价运输项目$2.0.8
 */
@Route(path = AppRouteConstant.WuLui.ROUTER_PATH_FREIGHTPRJDETAILACTIVITY)
public class FreightPrjDetailActivity extends AppActivity implements FreightPrjDetailAdapter.ItemOnClickListen {
    private ActivityFreightDetailBiddingBinding mBinding;
    //前台标题||个人中心标题:竞价单位
    private FreightPrjDetailAdapter mAdapter;
    private List<GoodsSourceDetail> getManageItemData = new ArrayList<>();
    GoodsDetailModel mModel;
    private String[] personTitles = {"项目信息", "报价要求", "结算要求", "其他约定"};
    private String[] frountTitles = {"项目信息", "报价要求", "结算要求", "其他约定", "竞价单位"};
    private String sourceNo;
    private GoodsSourceDetail mGoodsSourceDetail = null;
    String company;
    private Timer timer;
    private boolean IsPersonalCenter = false;//是个人中心
    private boolean IsOrder;//是订单详情
    private boolean isTakeOrders = false;//是否是接单
    LogisticsFlowLog flowLog;

    @Override
    protected void initView() {
        mBinding = DataBindingUtil.setContentView(FreightPrjDetailActivity.this, R.layout.activity_freight_detail_bidding);
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        mModel = new ViewModelProvider(this).get(GoodsDetailModel.class);
        initEvent();
        initData();
    }

    //goodsType竞价1和普通0   position大厅false和个人中心ture
    public static void start(Context context, String sourceNo, boolean isOrder, boolean position) {
        Intent intent = new Intent();
        intent.putExtra("sourceNo", sourceNo);
        intent.putExtra("goodsType", isOrder);
        intent.putExtra("position", position);
        intent.setClass(context, GeneralPrjDetailActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(intent);
    }

    private void initData() {
        mModel.upAndDownGoods.observe(this, list -> {
            downAndUpGoods();
        });
        mModel.deleteInfoSuccess.observe(this, list -> {
            deleteInfoSuccess();
        });
        mModel.confirmFundAccountData.observe(this, list -> {
            getGoodsOwnerInfo(list);
        });
        mModel.GoodsSourceDetailDataEmpty.observe(this, list -> {
            showEmptyView(list);
        });
        mModel.setUserInfo.observe(this, userData -> {
            if (userData == null) {
                VerificationCodeLoginActivity.start(this);
                return;
            }
            if (isTakeOrders) {
                LogisticsPermissionHelper.getInstance().checkPermissionToQuoteOrder(
                        this, mGoodsSourceDetail.getNo(), mGoodsSourceDetail.getTerminal(), mGoodsSourceDetail.getMessagePrice()
                );
            } else {
                LogisticsPermissionHelper.getInstance().checkPermissionToQuote(
                        this, mGoodsSourceDetail.getNo(), mGoodsSourceDetail.getTerminal(), mGoodsSourceDetail.getMessagePrice()
                );
            }
        });
    }

    private void initEvent() {
        sourceNo = getIntent().getStringExtra("sourceNo");
        IsPersonalCenter = getIntent().getBooleanExtra("position", false);
        IsOrder = getIntent().getBooleanExtra("goodsType", false);
        Request();
        mBinding.topLayout.ivBack.setOnClickListener(v -> finish());
        mBinding.onTheShelf.setOnClickListener(this);
        mBinding.editing.setOnClickListener(this);
        mBinding.delete.setOnClickListener(this);
        mBinding.tvReport.setOnClickListener(this);
        mBinding.tvContactService.setOnClickListener(this);
        mBinding.tvInquireByLetter.setOnClickListener(this);
        mBinding.tvCommit.setOnClickListener(this);
        mBinding.tvTakeOrders.setOnClickListener(this);
        mBinding.ggtDituIcon.setOnClickListener(this);
        mBinding.consignorGgtDituIcon.setOnClickListener(this);
        mBinding.offerNum.setOnClickListener(this);
        mBinding.takeOrdersNum.setOnClickListener(this);
        mBinding.headeCompay.callPhone.setOnClickListener(this);
        mBinding.bottomCompay.callPhone.setOnClickListener(this);
        mBinding.carRl.setOnClickListener(this);
        mBinding.intentionalCar.setOnClickListener(this);
        mBinding.contact1PersonText.setOnClickListener(this);
        mBinding.contact2PersonText.setOnClickListener(this);
        mBinding.contact3PersonText.setOnClickListener(this);
        mBinding.tvInvitation.setOnClickListener(this);
        mBinding.managerStatusFigureOperation.setOnClickListener(this);
        mBinding.tvFigureOperation.setOnClickListener(this);
        mBinding.quotationIcon.setOnClickListener(this);

        if (IsPersonalCenter) {
            mBinding.topLayout.shareImageView.setVisibility(View.GONE);
        } else {
            mBinding.topLayout.shareImageView.setVisibility(View.VISIBLE);
            mBinding.topLayout.shareImageView.setOnClickListener(this);
        }
    }


    private void initTabView() {
        if (mBinding.tablayout.getTabCount()>0){
            mBinding.tablayout.removeAllTabs();
        }
         if ((UserOperating.getInstance().isCompany() && UserOperating.getInstance().getTeamOrCompanyNameNo().equals(mGoodsSourceDetail.getCompanyNo()) && mGoodsSourceDetail.getTerminal() == 1)
                || (UserOperating.getInstance().isTeam() && UserOperating.getInstance().getTeamOrCompanyNameNo().equals(mGoodsSourceDetail.getTeamNo()) && mGoodsSourceDetail.getTerminal() == 2)
                || (UserOperating.getInstance().isPersonal() && UserOperating.getInstance().getUserNo().equals(mGoodsSourceDetail.getUserNo()) && mGoodsSourceDetail.getTerminal() == 3)) {
             for (String s : IsPersonalCenter || IsOrder ? personTitles : frountTitles) {
                 mBinding.tablayout.addTab(mBinding.tablayout.newTab().setText(s));
             }

         }else {
             for (String s : personTitles ) {
                 mBinding.tablayout.addTab(mBinding.tablayout.newTab().setText(s));
             }
         }
        mBinding.tablayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {

                mBinding.tablayout.setTag(tab.getTag());
                if (getManageItemData != null) {
                    getManageItemData.get(0).setItemType(tab.getPosition());
                }
                mAdapter.setNewData(getManageItemData);
                mAdapter.notifyDataSetChanged();
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    private void Request() {
        mModel.GeneralPrjDetailModel(this, sourceNo,IsPersonalCenter?1:null);
        mModel.GoodsSourceDetailData.observe(this, list -> {
            setDetail(list);
        });
    }

    @SuppressLint("ResourceAsColor")
    public void setDetail(GoodsSourceDetail manageItemData) {
        if (IsOrder) {
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mBinding.reInfomeation.getLayoutParams();
            params.setMargins(0, 20, 0, 0);
            mBinding.reInfomeation.setLayoutParams(params);
        }
        mBinding.topLayout.titleView.setText(IsOrder ? "竞价货运项目" : IsPersonalCenter ? "竞价货运项目" : (TextUtils.isEmpty(manageItemData.getProjectName()) ? NumberUtil.trim0(manageItemData.getWeight()) + "吨" + CargoConstant.getLastGoodsTypeName(manageItemData.getGoodsTypeName(),manageItemData.getSecondGoodsTypeName()) + "运输项目" : manageItemData.getProjectName()));
        mBinding.orderReceivingProcess.setVisibility(IsOrder ? View.GONE : IsPersonalCenter ? View.GONE : View.VISIBLE);
        mBinding.contnetLayout.setVisibility(View.VISIBLE);
        mBinding.tablayout.selectTab(mBinding.tablayout.getTabAt(0));
        mGoodsSourceDetail = manageItemData;
        if (manageItemData == null)
            return;
        if (getManageItemData == null) {
            getManageItemData.add(manageItemData);
        } else {
            getManageItemData.clear();
            getManageItemData.add(manageItemData);

        }

        mAdapter = new FreightPrjDetailAdapter(this, getManageItemData, IsOrder, IsPersonalCenter);
        mAdapter.SetItemOnClickListen(this);
        mBinding.recyclerViewContent.setLayoutManager(new LinearLayoutManager(getActivity()));
        mBinding.recyclerViewContent.setAdapter(mAdapter);
        setShow(manageItemData);
        setCompanyInfo(manageItemData);
        setGoodsInfo(manageItemData);
        setOffNumShow(manageItemData);
        if (IsOrder) {
            mBinding.managerStatus.setVisibility(View.GONE);
            mBinding.goodsStatusIcon.setBackgroundResource(R.color.white);
            mBinding.goodsUpdateTime.setTextColor(Color.parseColor("#666666"));
            mBinding.goodsEndTime.setTextColor(Color.parseColor("#666666"));
            mBinding.goodsUpdateTime.setText("货源更新时间    " + DateUtils.stampToMinute("" + manageItemData.getUpdateTime()));
            mBinding.goodsEndTime.setVisibility(manageItemData.getEndTime() == null ? View.GONE : View.VISIBLE);
            mBinding.goodsEndTime.setText("报价截止时间    " + (manageItemData.getEndTime() == null ? "" : DateUtils.stampToMinute("" + manageItemData.getEndTime())));
            mBinding.goodsUpdateTime.setPadding(0, 20, 0, 0);
        } else {
            setStateInfo(manageItemData);
        }
        if (!TextUtils.isEmpty(manageItemData.getConnection()) && !TextUtils.isEmpty(manageItemData.getConnectionPhone())) {
            mBinding.contact1Person.setVisibility(View.VISIBLE);
            mBinding.contact1PersonName.setText(manageItemData.getConnection());
            mBinding.contact1PersonText.setText(manageItemData.getConnectionPhone());
            if (IsPersonalCenter) {
                mBinding.contact1PersonText.setTextColor(getResources().getColor(R.color.FF333333));
                mBinding.contact1PersonText.setCompoundDrawables(null, null, null, null);
            }
        } else {
            showDiyInfo(manageItemData);
        }
        //判断是否货主身份
        if ((UserOperating.getInstance().isCompany() && UserOperating.getInstance().getTeamOrCompanyNameNo().equals(mGoodsSourceDetail.getCompanyNo()) && mGoodsSourceDetail.getTerminal() == 1)
                || (UserOperating.getInstance().isTeam() && UserOperating.getInstance().getTeamOrCompanyNameNo().equals(mGoodsSourceDetail.getTeamNo()) && mGoodsSourceDetail.getTerminal() == 2)
                || (UserOperating.getInstance().isPersonal() && UserOperating.getInstance().getUserNo().equals(mGoodsSourceDetail.getUserNo()) && mGoodsSourceDetail.getTerminal() == 3)) {
            mBinding.tvFigureOperation.setVisibility(View.VISIBLE);
            mBinding.managerStatusFigureOperation.setVisibility(View.VISIBLE);
            mBinding.quotationIcon.setVisibility(View.VISIBLE);
        } else {
            mBinding.tvFigureOperation.setVisibility(View.GONE);
            mBinding.managerStatusFigureOperation.setVisibility(IsPersonalCenter?View.VISIBLE:View.GONE);
            mBinding.quotationIcon.setVisibility(View.INVISIBLE);
        }
        initTabView();
    }

    private void setShow(GoodsSourceDetail manageItemData) {
        mBinding.frontBottom.setVisibility(IsOrder ? View.GONE : IsPersonalCenter ? View.GONE : View.VISIBLE);
        mBinding.quotationBottom.setVisibility(IsOrder ? View.GONE : IsPersonalCenter ? View.GONE : View.VISIBLE);
        mBinding.goodsLayout.setVisibility(IsOrder ? View.GONE : IsPersonalCenter ? View.VISIBLE : View.GONE);
        mBinding.cutoffTime.setVisibility(IsOrder ? View.GONE : IsPersonalCenter ? View.GONE : View.VISIBLE);
        mBinding.headLlCompay.setVisibility(IsOrder ? View.GONE : IsPersonalCenter ? View.GONE : View.VISIBLE);
        mBinding.managerStatusLl.setVisibility(IsOrder?View.GONE:View.VISIBLE);
    }

    private void setGoodsInfo(GoodsSourceDetail manageItemData) {
        if (IsPersonalCenter) {
            mBinding.onTheShelf.setText("1".equals(manageItemData.getStatus()) ? "下架" : "上架");
        }
        StringBuilder goodType = new StringBuilder();
        if (!TextUtils.isEmpty(manageItemData.getGoodsTypeName())){
            goodType.append(manageItemData.getGoodsTypeName());
        }
        if (!TextUtils.isEmpty(manageItemData.getSecondGoodsTypeName())){
            goodType.append(TextUtils.isEmpty(manageItemData.getGoodsTypeName())?manageItemData.getSecondGoodsTypeName():"/"+manageItemData.getSecondGoodsTypeName());
        }

        mBinding.gtdGoodsNameText.setText(TextUtils.isEmpty(manageItemData.getGoodsTypeName())&&TextUtils.isEmpty(manageItemData.getSecondGoodsTypeName())?"/":goodType);
        if (TextUtils.isEmpty(manageItemData.getWeight())) {
            if (!TextUtils.isEmpty(manageItemData.getVolume())) {
                mBinding.gtdFreightVolumeText.setText(NumberUtil.trim0(manageItemData.getVolume()) + "方");
            } else {
                mBinding.gtdFreightVolumeText.setText("/");
            }
        } else {
            mBinding.gtdFreightVolumeText.setText(NumberUtil.trim0(manageItemData.getWeight()) + "吨" + (TextUtils.isEmpty(manageItemData.getVolume()) ? "" : "  " + NumberUtil.trim0(manageItemData.getVolume()) + "方"));
        }
        mBinding.gtdFreightUnitPrice.setVisibility(manageItemData.getFreightType() == null||manageItemData.getFreightType()==0 ? View.VISIBLE : View.GONE);
        mBinding.gtdFreightUnitPriceText.setVisibility(manageItemData.getFreightType() == null||manageItemData.getFreightType()==0 ? View.VISIBLE : View.GONE);
        mBinding.gtdFreightUnitPriceText.setText(NumberUtil.trim0(manageItemData.getFreight()) + manageItemData.getFreightUnitType());
        mBinding.rlInvoice.setVisibility(TextUtils.isEmpty(manageItemData.getInvoiceWords()) ? View.GONE : View.VISIBLE);
        mBinding.gtdInvoiceRequirementText.setText(TextUtils.isEmpty(manageItemData.getInvoiceWords()) ? "/" : manageItemData.getInvoiceWords().equals("不开发票") ? manageItemData.getInvoiceWords():
                NumberUtil.trim0(manageItemData.getTariff()) + "%" + manageItemData.getInvoiceWords());
        StringBuilder builder = new StringBuilder();
        if (!TextUtils.isEmpty(manageItemData.getPrepaidProportion()) && !manageItemData.getPrepaidProportion().equals("0")) {
            builder.append("预付款").append(manageItemData.getPrepaidProportion()).append("%，");
        }
        if (manageItemData.getPaymentAfterLoading() != 0) {
            builder.append("装车后支付").append(manageItemData.getPaymentAfterLoading()).append("%，");
        }
        if (manageItemData.getArrivalAcceptancePayment() != 0) {
            builder.append("到货验收后支付").append(manageItemData.getArrivalAcceptancePayment()).append("%（尾款由验收人验收后支付），");
        }
        if (builder.length() > 1) {
            mBinding.gtdPaymentMethodTextAx.setText(builder.substring(0, builder.length() - 1));
            mBinding.gtdPaymentMethodTextAx.setVisibility(View.VISIBLE);
        } else {
            mBinding.gtdPaymentMethodTextAx.setVisibility(View.GONE);
        }
        mBinding.rlPayment.setVisibility(TextUtils.isEmpty(manageItemData.getPayType()) ? View.GONE : View.VISIBLE);
        mBinding.gtdPaymentMethodText.setText(TextUtils.isEmpty(manageItemData.getPayType()) ? "/" : manageItemData.getPayType());
        mBinding.receivingRl.setVisibility(TextUtils.isEmpty(manageItemData.getDestDetailAddress()) ? View.GONE : View.VISIBLE);
        mBinding.gtdConsignorRl.setVisibility(TextUtils.isEmpty(manageItemData.getDetailAddress()) ? View.GONE : View.VISIBLE);
        mBinding.gtdConsignorAddressText.setText(TextUtils.isEmpty(manageItemData.getDetailAddress()) ? "/" :manageItemData.getProvinceName()+manageItemData.getCityName()+manageItemData.getDistrictName()+manageItemData.getDetailAddress());
        mBinding.gtdReceivingAddressText.setText(TextUtils.isEmpty(manageItemData.getDestDetailAddress()) ? "/" : manageItemData.getDestProvinceName()+manageItemData.getDestCityName()+manageItemData.getDestDistrictName()+manageItemData.getDestDetailAddress());
        mBinding.showLl.setVisibility(TextUtils.isEmpty(manageItemData.getPerformanceBond()) ? View.GONE : View.VISIBLE);
        mBinding.rlSecurityDeposit.setVisibility(TextUtils.isEmpty(manageItemData.getPerformanceBond()) ? View.GONE : View.VISIBLE);
        mBinding.securityDepositText.setTextColor(TextUtils.isEmpty(manageItemData.getPerformanceBond()) ? getResources().getColor(R.color.color_333333) : getResources().getColor(R.color.color_FF4B10));
        mBinding.securityDepositText.setText(TextUtils.isEmpty(manageItemData.getPerformanceBond()) ? "/" : "0".equals(NumberUtil.trim0(manageItemData.getPerformanceBond())) ? "/" : NumberUtil.trim0(manageItemData.getPerformanceBond()) + "元");
    }

    /**
     * 新增字段显示隐藏操作
     */
    private void showDiyInfo(GoodsSourceDetail info) {
        View[] layoutArray = {mBinding.contact1Person, mBinding.contact2Person, mBinding.contact3Person};
        TextView[] diyFiledKeyArray = {mBinding.contact1PersonName, mBinding.contact2PersonName, mBinding.contact3PersonName};
        TextView[] diyFiledValueArray = {mBinding.contact1PersonText, mBinding.contact2PersonText, mBinding.contact3PersonText};
        if (info.getContactInfo() == null || info.getContactInfo().size() == 0) {
            return;
        }
        //因为这里限制了最多三条，所以在这里添加一个保护
        if (info.getContactInfo().size() > 3) {
            info.setContactInfo(info.getContactInfo().subList(0, 3));
        }
        for (int i = 0; i < info.getContactInfo().size(); i++) {
            layoutArray[i].setVisibility(View.VISIBLE);
            diyFiledKeyArray[i].setText(info.getContactInfo().get(i).getContrcts());
            CharSequence styledText = Html.fromHtml(DefaultUtil.getString((info.getContactInfo().get(i).getContrctsNumber())));
            diyFiledValueArray[i].setText(DefaultUtil.getString(styledText.toString()));

            if (IsPersonalCenter) {
                diyFiledValueArray[i].setTextColor(getResources().getColor(R.color.FF333333));
                diyFiledValueArray[i].setCompoundDrawables(null, null, null, null);
            }
        }
    }

    /**
     * 状态判断
     * 0 是普通货源详情（显示接单tag）反之显示竞价时间标识 1 已完成（普通货源）2 竞价货源截止
     * （待接单、已成交、已失效）普通货源详情/（竞价中、已结束、已失效）竞价详情【大厅/货主】
     * 货源状态 0 待接单（接单中）/竞价中 1 已成交/已转订单 2 已结束/待处理 3 已失效 4 报价截止 5 已下架
     */
    private void setStateInfo(GoodsSourceDetail info) {
        if (info.getState() == null)
            return;
        if (CargoConstant.stampFormatLoadInput(info.getShipmentTime(), info.getStartPointTime()).equals(CargoConstant.stampFormatLoadInput(info.getShipmentEndTime(), info.getEndPointTime()))) {
            mBinding.goodsUpdateTime.setText((IsPersonalCenter?"装货时间    ":"装货时间    " )+ CargoConstant.stampFormatLoadInput(info.getShipmentTime(), info.getStartPointTime()));
        } else {
            mBinding.goodsUpdateTime.setText((IsPersonalCenter?"装货时间    ":"装货时间    " )+ CargoConstant.stampFormatLoadInput(info.getShipmentTime(), info.getStartPointTime()) + (TextUtils.isEmpty(CargoConstant.stampFormatLoadInput(info.getShipmentEndTime(), info.getEndPointTime())) ? "" : "-") + CargoConstant.stampFormatLoadInput(info.getShipmentEndTime(), info.getEndPointTime()));
        }

        switch (info.getState()) {
            case CargoConstant.BiddingCargoMode.MODE_BIDDING:
                mBinding.managerStatus.setText("竞价中");
                if (info.getEndTime() == null || info.getEndTime() == 0) {
                    mBinding.carRl.setVisibility(View.GONE);
                    mBinding.cutoffTime.setVisibility(View.GONE);
                    mBinding.quotationBottom.setVisibility(View.GONE);
                    mBinding.viewBackgroundWhite.setVisibility(View.GONE);
                } else {
                    if (timer == null) {
                        timer = new Timer();
                    }
                   /* timer.schedule(new TimerTask() {
                        @Override
                        public void run() {
                            runOnUiThread(() -> mBinding.quotationTime.setText(DateUtils.dateDiff(DateUtils.stampToDay6("" + info.getEndTime()))));
                        }
                    }, 0, 1000);*/
                    if (!TextUtils.isEmpty(info.getLowestPrice()) && !NumberUtil.trim0(info.getLowestPrice()).equals("0")) {
                        mBinding.lowestQuotationText.setText((NumberUtil.trim0(info.getLowestPrice()) + "元/吨"));
                    } else {
                        mBinding.lowestQuotationText.setText("无人报价");
                    }
                    mBinding.intentionalCar.setText(Html.fromHtml("<font size='12px'>意向人数：</font>" + ("<font color='#666666' size='20px'>" + NumberUtil.trim0(info.getIntentionCarNumber()) + "" + "</font>")));
                    mBinding.frontBottom.setVisibility(IsPersonalCenter ? View.GONE : View.VISIBLE);
                    mBinding.tvCommit.setEnabled(true);
                    mBinding.tvCommit.setAlpha((float) 1);
                    mBinding.tvTakeOrders.setEnabled(true);
                    mBinding.tvTakeOrders.setAlpha((float) 1);
                    mBinding.quotationBottom.setVisibility(TextUtils.isEmpty(info.getLastFreight()) ? View.GONE : View.VISIBLE);
                    mBinding.viewBackgroundWhite.setVisibility(TextUtils.isEmpty(info.getLastFreight()) ? View.GONE : View.VISIBLE);
//                    mBinding.quotationBottom.setBackgroundColor(Color.parseColor("#99010101"));
                    if (mBinding.quotationBottom.getVisibility() == View.VISIBLE) {
                        mBinding.lvLinearlayout.setPadding(0, 0, 0, 60);
                    }

                    mBinding.quotationText.setText(info.getLastFreight());
                    setLoadTimeBing(info);
                    if (info.hasOfferAgreed()) {
                        mBinding.goodsLayout.setVisibility(View.GONE);
                    }else {
                        if (IsPersonalCenter){
                            mBinding.goodsLayout.setVisibility(View.VISIBLE);
                        }
                    }
                    mBinding.onTheShelf.setTextColor(Color.parseColor("#333333"));
                }
                break;
            case CargoConstant.BiddingCargoMode.MODE_DEAL_DOWN:
                mBinding.viewBackgroundWhite.setVisibility(View.GONE);
                mBinding.quotationBottom.setVisibility(View.GONE);
                mBinding.cutoffTime.setVisibility(View.GONE);
                mBinding.managerStatus.setText("已成交");
                if (IsPersonalCenter){
                    if (info.getEndTime() == null) {
                        mBinding.goodsEndTime.setVisibility(View.GONE);
                    } else {
                        mBinding.goodsEndTime.setVisibility(View.VISIBLE);
                        mBinding.goodsEndTime.setText("报价截止时间    " + DateUtils.stampToMinute("" + info.getEndTime()));
                    }
                }
                mBinding.editing.setTextColor(Color.parseColor("#969696"));
                mBinding.delete.setTextColor(Color.parseColor("#969696"));
                mBinding.editing.setEnabled(false);
                mBinding.delete.setEnabled(false);
                break;
            case 2:
                mBinding.quotationBottom.setVisibility(View.GONE);
                if (IsPersonalCenter) {
                    mBinding.goodsLayout.setVisibility(View.VISIBLE);
                    mBinding.viewBackgroundWhite.setVisibility(View.GONE);
                    mBinding.cutoffTime.setVisibility(View.GONE);
                    mBinding.managerStatus.setText("已失效");
                    mBinding.onTheShelf.setEnabled(false);
                    mBinding.editing.setEnabled(false);
                    mBinding.onTheShelf.setTextColor(Color.parseColor("#969696"));
                    mBinding.editing.setTextColor(Color.parseColor("#969696"));
                    setLoadTimeBing(mGoodsSourceDetail);
                }else {
                    setState(info);
                }
                break;
            case 3://付款中
                mBinding.viewBackgroundWhite.setVisibility(View.GONE);
                mBinding.quotationBottom.setVisibility(View.GONE);
                mBinding.cutoffTime.setVisibility(View.GONE);
                mBinding.editing.setTextColor(Color.parseColor("#969696"));
                mBinding.editing.setEnabled(false);
                break;
            case CargoConstant.BiddingCargoMode.MODE_DEADLINE:
                mBinding.viewBackgroundWhite.setVisibility(View.GONE);
                mBinding.quotationBottom.setVisibility(View.GONE);
                mBinding.delete.setEnabled(!info.hasOfferAgreed());
                mBinding.editing.setEnabled(!info.hasOfferAgreed());
                mBinding.delete.setTextColor(!info.hasOfferAgreed() ? Color.parseColor("#ef4033") : Color.parseColor("#969696"));
                mBinding.editing.setTextColor(!info.hasOfferAgreed() ? Color.parseColor("#333333") : Color.parseColor("#969696"));
                mBinding.onTheShelf.setEnabled(false);
                mBinding.onTheShelf.setTextColor(Color.parseColor("#969696"));
                setState(info);
                setLoadTimeBing(mGoodsSourceDetail);
                break;
            case CargoConstant.BiddingCargoMode.MODE_DOWN:
                mBinding.viewBackgroundWhite.setVisibility(View.GONE);
                mBinding.cutoffTime.setVisibility(View.GONE);
                mBinding.quotationBottom.setVisibility(View.GONE);
                mBinding.managerStatus.setText("已下架");
                mBinding.tvCommit.setEnabled(false);
                mBinding.tvCommit.setAlpha((float) 0.6);
                mBinding.tvTakeOrders.setEnabled(false);
                mBinding.tvTakeOrders.setAlpha((float) 0.6);
                mBinding.onTheShelf.setText("1".equals(info.getStatus()) ? "下架" : "上架");
                break;

        }

    }

    public void setOffNumShow(GoodsSourceDetail info) {
        if (IsPersonalCenter && !IsOrder) {
            mBinding.offerNum.setVisibility(View.VISIBLE);
            mBinding.takeOrdersNum.setVisibility(View.VISIBLE);
            mBinding.goodsLayout.setVisibility(View.GONE);
            if (info.getOfferNum() == null || info.getOfferNum() == 0) {
                mBinding.offerNum.setText("0" + "家单位报价");
                mBinding.goodsLayout.setVisibility(View.VISIBLE);
            } else {
                mBinding.goodsLayout.setVisibility(View.GONE);
                if (info.getOfferNum()>99){
                    mBinding.offerNum.setText("99+家单位报价");
                }else {
                    mBinding.offerNum.setText(info.getOfferNum() + "家单位报价");
                }
            }
            if (info.getBiddingSupplyOrderNum() == null || info.getBiddingSupplyOrderNum() == 0) {
                mBinding.takeOrdersNum.setText("0" + "家单位接单");
                mBinding.goodsLayout.setVisibility(View.VISIBLE);
            } else {
                mBinding.goodsLayout.setVisibility(View.GONE);
                if (info.getBiddingSupplyOrderNum()>99){
                    mBinding.takeOrdersNum.setText("99+家单位接单");
                }else {
                    mBinding.takeOrdersNum.setText(info.getBiddingSupplyOrderNum() + "家单位接单");
                }
            }
        }
    }

    public void setLoadTimeBing(GoodsSourceDetail info) {
        if (IsPersonalCenter) {
            if (CargoConstant.stampFormatLoadInput(info.getShipmentTime(), info.getStartPointTime()).equals(CargoConstant.stampFormatLoadInput(info.getShipmentEndTime(), info.getEndPointTime()))) {
                mBinding.goodsUpdateTime.setText("装货时间    " + CargoConstant.stampFormatLoadInput(info.getShipmentTime(), info.getStartPointTime()));
            } else {
                mBinding.goodsUpdateTime.setText("装货时间    " + CargoConstant.stampFormatLoadInput(info.getShipmentTime(), info.getStartPointTime()) + (TextUtils.isEmpty(CargoConstant.stampFormatLoadInput(info.getShipmentEndTime(), info.getEndPointTime())) ? "" : "-") + CargoConstant.stampFormatLoadInput(info.getShipmentEndTime(), info.getEndPointTime()));
            }
            if (info.getEndTime() == null) {
                mBinding.goodsEndTime.setVisibility(View.GONE);
            } else {
                mBinding.goodsEndTime.setVisibility(View.VISIBLE);
                mBinding.goodsEndTime.setText("报价截止时间    " + DateUtils.stampToMinute("" + info.getEndTime()));
            }
        } else {
            mBinding.goodsEndTime.setVisibility(View.GONE);
        }
        if (info.getShipmentTime() == null) {
            mBinding.goodsUpdateTime.setVisibility(View.GONE);
            return;
        }
        if (IsPersonalCenter&&info.getState()!=2&&info.getState()!=CargoConstant.BiddingCargoMode.MODE_DEADLINE) {
            mBinding.cutoffTime.setVisibility(View.GONE);
            if (CargoConstant.stampFormatLoadInput(info.getShipmentTime(), info.getStartPointTime()).equals(CargoConstant.stampFormatLoadInput(info.getShipmentEndTime(), info.getEndPointTime()))) {
                mBinding.goodsUpdateTime.setText("装货时间    " + CargoConstant.stampFormatLoadInput(info.getShipmentTime(), info.getStartPointTime()));
            } else {
                mBinding.goodsUpdateTime.setText("装货时间    " + CargoConstant.stampFormatLoadInput(info.getShipmentTime(), info.getStartPointTime()) + (TextUtils.isEmpty(CargoConstant.stampFormatLoadInput(info.getShipmentEndTime(), info.getEndPointTime())) ? "" : "-") + CargoConstant.stampFormatLoadInput(info.getShipmentEndTime(), info.getEndPointTime()));
            }
            if (info.getEndTime() == null) {
                mBinding.goodsEndTime.setVisibility(View.GONE);
            } else {
                mBinding.goodsEndTime.setVisibility(View.VISIBLE);
                mBinding.goodsEndTime.setText("报价截止时间    " + DateUtils.stampToMinute("" + info.getEndTime()));
            }
        } else {
            if (CargoConstant.stampFormatLoadInput(info.getShipmentTime(), info.getStartPointTime()).equals(CargoConstant.stampFormatLoadInput(info.getShipmentEndTime(), info.getEndPointTime()))) {
                mBinding.goodsUpdateTime.setText("装货时间    " + CargoConstant.stampFormatLoadInput(info.getShipmentTime(), info.getStartPointTime()));
            } else {
                mBinding.goodsUpdateTime.setText("装货时间    " + CargoConstant.stampFormatLoadInput(info.getShipmentTime(), info.getStartPointTime()) + (TextUtils.isEmpty(CargoConstant.stampFormatLoadInput(info.getShipmentEndTime(), info.getEndPointTime())) ? "" : "-") + CargoConstant.stampFormatLoadInput(info.getShipmentEndTime(), info.getEndPointTime()));
            }
        }
        if (!IsPersonalCenter){
            mBinding.goodsEndTime.setVisibility(info.getState()==0?View.GONE:View.VISIBLE);
        }
    }

    private void setState(GoodsSourceDetail info) {
        if (IsPersonalCenter) {
            if (CargoConstant.stampFormatLoadInput(info.getShipmentTime(), info.getStartPointTime()).equals(CargoConstant.stampFormatLoadInput(info.getShipmentEndTime(), info.getEndPointTime()))) {
                mBinding.goodsUpdateTime.setText("装货时间    " + CargoConstant.stampFormatLoadInput(info.getShipmentTime(), info.getStartPointTime()));
            } else {
                mBinding.goodsUpdateTime.setText("装货时间    " + CargoConstant.stampFormatLoadInput(info.getShipmentTime(), info.getStartPointTime()) + (TextUtils.isEmpty(CargoConstant.stampFormatLoadInput(info.getShipmentEndTime(), info.getEndPointTime())) ? "" : "-") + CargoConstant.stampFormatLoadInput(info.getShipmentEndTime(), info.getEndPointTime()));
            }
        }else {
            mBinding.goodsUpdateTime.setText("货源更新时间    " + DateUtils.stampToMinute("" + info.getUpdateTime()));
        }
        mBinding.goodsEndTime.setVisibility(info.getEndTime() == null ? View.GONE : View.VISIBLE);
        mBinding.goodsEndTime.setText("报价截止时间    " + (info.getEndTime() == null ? "" : DateUtils.stampToMinute("" + info.getEndTime())));
        mBinding.tvCommit.setEnabled(false);
        mBinding.tvCommit.setAlpha((float) 0.6);
        mBinding.tvTakeOrders.setEnabled(false);
        mBinding.tvTakeOrders.setAlpha((float) 0.6);
        mBinding.cutoffTime.setVisibility(View.GONE);
        mBinding.managerStatus.setText("报价已截止");
        mBinding.carRl.setVisibility(View.GONE);
        mBinding.quotationReason.setVisibility(View.VISIBLE);
        if (TextUtils.isEmpty(info.getEndReason())) {
            mBinding.quotationReason.setText(info.getEndTime() == null ? "" : "截止原因    已超过报价截止时间。报价截止时间" );
        } else {
            mBinding.quotationReason.setText("截止原因    " + info.getEndReason());
        }

    }

    /**
     * 点击事件
     */
    @Override
    public void onMultiClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.on_the_shelf:
                dropOffDialog();
                break;
            case R.id.editing:
                ReleaseCargoActivity.start(getActivity(), mGoodsSourceDetail.getNo(), false);
                break;
            case R.id.delete:
                showDelDialog();
                break;
            case R.id.tv_report:
                //TODO
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(FreightPrjDetailActivity.this);
                    return;
                }
                flowLog=new LogisticsFlowLog("4","货源联系人","button");
                showConsignorDialog(mGoodsSourceDetail.getConnectionPhone());
                //ReportActivity.start(this, sourceNo, "2");
                break;
            case R.id.tv_contact_service:
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(FreightPrjDetailActivity.this);
                    return;
                }
                if (!contactsIsInSystem()) {
                    return;
                }
                if (mGoodsSourceDetail != null) {
                    // TODO IM功能目前需要全部去掉，此处需要后期IM迁移完成后完善
                    if (!TextUtils.isEmpty(mGoodsSourceDetail.getContrctsImAccount())){
                        buildSingleTalking(mGoodsSourceDetail.getContrctsImAccount());
                    }else {
                        if (!TextUtils.isEmpty(mGoodsSourceDetail.getImAccount())){
                            buildSingleTalking(mGoodsSourceDetail.getImAccount());
                        }
                    }
                }
                break;
            case R.id.tv_inquire_by_letter:
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(FreightPrjDetailActivity.this);
                    return;
                }
                //TODO 函询
                InquireByLetterActvity.start(this, 1, mGoodsSourceDetail.getConnection(), mGoodsSourceDetail.getUserNo(), mGoodsSourceDetail.getNo(), mGoodsSourceDetail.getCityName() + "\u3000" + mGoodsSourceDetail.getDistrictName() + "->" + mGoodsSourceDetail.getDestCityName() + "\u3000" + mGoodsSourceDetail.getDestCityName());
                break;
            case R.id.tv_commit:
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(FreightPrjDetailActivity.this);
                    return;
                }else {
                    mModel.refresh(this);
                    isTakeOrders = false;
                }
                break;
            case R.id.tv_take_orders:
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(FreightPrjDetailActivity.this);
                    return;
                }else {
                    isTakeOrders = true;
                    mModel.refresh(this);
                }
                break;
            case R.id.consignor_ggt_ditu_icon:
                company = mGoodsSourceDetail.getTerminal() == 3 ? "" : mGoodsSourceDetail.getCompanyName();
                //TODO 地址详情点击事件
                GoodsSourcePlace place;
                if (mGoodsSourceDetail.getPlace() == null) {
                    place = EntityConversion.modelA2B(mGoodsSourceDetail, GoodsSourcePlace.class);
                } else {
                    place = mGoodsSourceDetail.getPlace();
                }
                switch (mGoodsSourceDetail.getHandleTypeNo()) {
                    case "11":
                        HandleAdressActivity.start(FreightPrjDetailActivity.this, mGoodsSourceDetail.getConnection(), company, mGoodsSourceDetail.getConnectionPhone(), mGoodsSourceDetail.getImAccount(), place, 0, "11");
                        break;
                    case "12":
                        HandleAdressActivity.start(FreightPrjDetailActivity.this, mGoodsSourceDetail.getConnection(), company, mGoodsSourceDetail.getConnectionPhone(), mGoodsSourceDetail.getImAccount(), place, 0, "12");
                        break;
                    case "21":
                        HandleAdressActivity.start(FreightPrjDetailActivity.this, mGoodsSourceDetail.getConnection(), company, mGoodsSourceDetail.getConnectionPhone(), mGoodsSourceDetail.getImAccount(), place, 0, "21");
                        break;
                    case "22":
                        HandleAdressActivity.start(FreightPrjDetailActivity.this, mGoodsSourceDetail.getConnection(), company, mGoodsSourceDetail.getConnectionPhone(), mGoodsSourceDetail.getImAccount(), place, 0, "22");
                        break;
                }
                break;
            case R.id.ggt_ditu_icon:
                company = mGoodsSourceDetail.getTerminal() == 3 ? "" : mGoodsSourceDetail.getCompanyName();
                //TODO 地址详情点击事件
                GoodsSourcePlace place1;
                if (mGoodsSourceDetail.getPlace() == null) {
                    place1 = EntityConversion.modelA2B(mGoodsSourceDetail, GoodsSourcePlace.class);
                } else {
                    place1 = mGoodsSourceDetail.getPlace();
                }
                switch (mGoodsSourceDetail.getHandleTypeNo()) {
                    case "11":
                        HandleAdressActivity.start(FreightPrjDetailActivity.this, mGoodsSourceDetail.getConnection(), company, mGoodsSourceDetail.getConnectionPhone(), mGoodsSourceDetail.getImAccount(), place1, 1, "11");
                        break;
                    case "12":
                        HandleAdressActivity.start(FreightPrjDetailActivity.this, mGoodsSourceDetail.getConnection(), company, mGoodsSourceDetail.getConnectionPhone(), mGoodsSourceDetail.getImAccount(), place1, 2, "12");
                        break;
                    case "21":
                        HandleAdressActivity.start(FreightPrjDetailActivity.this, mGoodsSourceDetail.getConnection(), company, mGoodsSourceDetail.getConnectionPhone(), mGoodsSourceDetail.getImAccount(), place1, 2, "21");
                        break;
                    case "22":
                        HandleAdressActivity.start(FreightPrjDetailActivity.this, mGoodsSourceDetail.getConnection(), company, mGoodsSourceDetail.getConnectionPhone(), mGoodsSourceDetail.getImAccount(), place1, 3, "22");
                        break;
                }
                break;
            case R.id.heade_compay:
                break;
            case R.id.offerNum:
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(FreightPrjDetailActivity.this);
                    return;
                }
                OfferOwnerListActivity.start(this, mGoodsSourceDetail.getNo(), false);
                break;
            case R.id.take_orders_num:
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(FreightPrjDetailActivity.this);
                    return;
                }
                OfferOwnerListActivity.start(this, mGoodsSourceDetail.getNo(), true);
                break;
            case R.id.quotation_icon:
            case R.id.manager_status_figure_operation:
            case R.id.tv_figure_operation:
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(FreightPrjDetailActivity.this);
                    return;
                }
                if (UserOperating.getInstance().isCompany() && UserOperating.getInstance().getTeamOrCompanyNameNo().equals(mGoodsSourceDetail.getCompanyNo()) && mGoodsSourceDetail.getTerminal() == 1) {
                    //当前是企业并且跟货源发布人一致
                    QuotedOwnerActivity.start(this, mGoodsSourceDetail.getNo());
                } else if (UserOperating.getInstance().isTeam() && UserOperating.getInstance().getTeamOrCompanyNameNo().equals(mGoodsSourceDetail.getTeamNo()) && mGoodsSourceDetail.getTerminal() == 2) {
                    //当前是团队并且跟货源发布人一致
                    QuotedOwnerActivity.start(this, mGoodsSourceDetail.getNo());
                } else if (UserOperating.getInstance().isPersonal() && UserOperating.getInstance().getUserNo().equals(mGoodsSourceDetail.getUserNo()) && mGoodsSourceDetail.getTerminal() == 3) {
                    //当前是个人并且跟货源发布人一致
                    QuotedOwnerActivity.start(this, mGoodsSourceDetail.getNo());
                } else {
                    QuotedThirdActivity.start(this, mGoodsSourceDetail.getNo());
                }
                break;
            case R.id.contact1_person_text:
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(FreightPrjDetailActivity.this);
                    return;
                }
                  if (!TextUtils.isEmpty(mGoodsSourceDetail.getConnection()) && !TextUtils.isEmpty(mGoodsSourceDetail.getConnectionPhone())) {
                      flowLog = new LogisticsFlowLog("4","货源联系人", "icon");
                  } else if(mGoodsSourceDetail.getContactInfo()!=null&&mGoodsSourceDetail.getContactInfo().size()>0&&mGoodsSourceDetail.getContactInfo().get(0).getContrcts()!=null) {
                    flowLog = new LogisticsFlowLog("4", "货源联系人", "icon");
                }
                showConsignorDialog(mBinding.contact1PersonText.getText().toString());
                break;
            case R.id.contact2_person_text:
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(FreightPrjDetailActivity.this);
                    return;
                }
                flowLog=new LogisticsFlowLog("4","货源联系人","icon");
                showConsignorDialog(mBinding.contact2PersonText.getText().toString());
                break;
            case R.id.contact3_person_text:
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(FreightPrjDetailActivity.this);
                    return;
                }
                flowLog=new LogisticsFlowLog("4","货源联系人","icon");
                showConsignorDialog(mBinding.contact3PersonText.getText().toString());

                break;
            case R.id.tv_invitation:
                LogisticsPermissionHelper.getInstance().checkPermissionToInvite(this,mGoodsSourceDetail.getCompanyNo(),mGoodsSourceDetail.getTerminal());
                break;
            case R.id.share_image_view://分享
                if (mGoodsSourceDetail == null)
                    return;
                StringBuilder title = new StringBuilder();
                StringBuilder content = new StringBuilder();
                if (!TextUtils.isEmpty(mGoodsSourceDetail.getCityName())) {
                    title.append(mGoodsSourceDetail.getCityName());
                }
                if (!TextUtils.isEmpty(mGoodsSourceDetail.getDistrictName())) {
                    title.append(" ").append(mGoodsSourceDetail.getCityName());
                }
                title.append(" → ");
                if (!TextUtils.isEmpty(mGoodsSourceDetail.getDestCityName())) {
                    title.append(mGoodsSourceDetail.getDestCityName());
                }
                if (!TextUtils.isEmpty(mGoodsSourceDetail.getDestDistrictName())) {
                    title.append(" ").append(mGoodsSourceDetail.getDestDistrictName());
                }
                String wightStr = (TextUtils.isEmpty(mGoodsSourceDetail.getWeight()) || TextUtils.isDigitsOnly(mGoodsSourceDetail.getWeight()) ? "" : "/" + NumberUtil.trim0(mGoodsSourceDetail.getWeight()) + "吨");
                String volumeStr = TextUtils.isEmpty(mGoodsSourceDetail.getVolume()) ? "" : "/" + NumberUtil.trim0(mGoodsSourceDetail.getVolume()) + "方";
                content.append(CargoConstant.getLastGoodsTypeName(mGoodsSourceDetail.getGoodsTypesName(), mGoodsSourceDetail.getSecondGoodsTypeName())).append(wightStr).append(volumeStr);

                ShareLogisticsActivity.start(FreightPrjDetailActivity.this, title.toString(), content.toString(), "", mGoodsSourceDetail.getShareUrl(), false);
                break;
        }
    }

    private boolean isLogin() {
        return !TextUtils.isEmpty(SharedPreferenceUtil.getInstance().
                getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""));
    }

    private boolean contactsIsInSystem() {
        if (mGoodsSourceDetail == null) {
            return false;
        }
        return !TextUtils.isEmpty(mGoodsSourceDetail.getContrctsImAccount()) || !TextUtils.isEmpty(mGoodsSourceDetail.getImAccount());

    }

    //功能正在开发
    public void showdevelopmentDialog() {
        new RoundDialog.Builder(this)
                .title("提示")
                .content("该功能正在开发中")
                .singleBtn(true)
                .confirm("确定")
                .contentGravity(Gravity.CENTER)
                .cancelable(false)
                .show();
    }

    /**
     * 删除提示
     */
    private void showDelDialog() {
        new RoundDialog.Builder(getActivity())
                .title("温馨提示")
                .content("确定删除吗？")
                .confirmCallback(v -> mModel.deleteGoods(this, String.valueOf(mGoodsSourceDetail.getId())))
                .show();
    }

    //打电话弹窗
    public void showConsignorDialog(String phone) {
        new RoundDialog.Builder(this)
                .title("确认呼叫")
                .content(phone)
                .cancel("取消")
                .confirm("确定")
                .contentGravity(Gravity.CENTER)
                .cancelable(false)
                .confirmCallback(new RoundDialog.SingleCallback() {
                    @Override
                    public void onClick(View v) {
                        if(flowLog!=null) {
                            LogisticsLogUtils.getInstance().logisticsFlow(flowLog);
                        }
                        callPhone(phone);
                    }
                })
                .show();
    }

    /**
     * 上下架提示
     */
    private void dropOffDialog() {
        new RoundDialog.Builder(getActivity())
                .title("1".equals(mGoodsSourceDetail.getStatus())
                        ? "下架"
                        : "上架")
                .content("1".equals(mGoodsSourceDetail.getStatus())
                        ? "下架后前台不展示此信息，\n确认下架吗？"
                        : "上架后前台展示此信息，确认上架吗？")
                .confirmCallback(v -> mModel.downAndUpGoods(this, mGoodsSourceDetail.getNo()))
                .show();
    }

    public void deleteInfoSuccess() {
        EventBus.getDefault().post(LogisticsEvent.make(EventConstant.EVENT_GOOD_DETAIL_DELETE, null));
        finish();
    }

    public void downAndUpGoods() {
        mModel.GeneralPrjDetailModel(this, sourceNo,IsPersonalCenter?1:null);
        mModel.GoodsSourceDetailData.observe(this, list -> {
            setDetail(list);
        });
        EventBus.getDefault().post(LogisticsEvent.make(EventConstant.EVENT_GOOD_DETAIL_UP_AND_DOWN_SUCCESS, null));
    }

    public void showEmptyView(String msg) {
        mBinding.noGoods.setVisibility(View.VISIBLE);
        mBinding.contnetLayout.setVisibility(View.GONE);
        mBinding.goodsTips.setText(msg);
    }

    /**
     * 检查车辆信息是否完善
     *
     * @param isComplete 未完善弹窗提示，跳转车辆信息编辑页面
     *                   已完善则跳转接单页面
     */
    public void checkCarInfoResult(boolean isComplete, CarInfo carInfo) {
        if (isComplete) {
            if (!UserOperating.getInstance().getUserInfo().isDriverOpenFundsAccount()) {
                new RoundDialog.Builder(this)
                        .title("提示")
                        .content("开通在线收款账户后\n可使用此功能")
                        .cancel("知道了")
                        .confirm("前往开户")
                        .contentGravity(Gravity.CENTER)
                        .cancelable(false)
                        .confirmCallback(view -> {
                            OpenAccountFirstActivity.start(this, true);
                        })
                        .show();
                return;
            }
            if (isTakeOrders) {
                PayBiddingOrderActivity.startForResult(this, mGoodsSourceDetail.getNo(), false, true, "");
            } else {
                CargoQuotationActivity.startForResult(this, mGoodsSourceDetail.getNo(), false, true, "");
            }
        } else {
            if (carInfo != null && !TextUtils.isDigitsOnly(carInfo.getCarNumber()))
                new RoundDialog.Builder(this)
                        .title("提示")
                        .content("请先完善" + carInfo.getCarNumber() + "的车辆信息")
                        .cancel("暂不完善")
                        .confirm("确定").confirmCallback(v -> {
                    Intent intent = new Intent(FreightPrjDetailActivity.this, AddCarInfoActivity.class);
//                            intent.putExtra("carId", carInfo.getId());
                    intent.putExtra("carNo", Long.valueOf(carInfo.getNo()));
                    startActivity(intent);
                }).show();
        }
    }

    //判断团队或企业是否开通资金账户
    public void getGoodsOwnerInfo(UserAccount userAccount) {
        if (mGoodsSourceDetail.getTerminal() == null) {
            return;
        }
        if (!userAccount.isIsDriverOpenFundsAccount() && mGoodsSourceDetail.getTerminal() == 2) {//货源货主团队没开通资金账户
            new RoundDialog.Builder(this)
                    .title("提示")
                    .content("货主未开通收款账户，无法报价")
                    .singleBtn(true)
                    .confirm("确定")
                    .contentGravity(Gravity.CENTER)
                    .cancelable(false)
                    .show();
        } else if (!userAccount.isIsOpenFundsAccount() && mGoodsSourceDetail.getTerminal() == 1) {//货源货主企业没开通资金账户
            new RoundDialog.Builder(this)
                    .title("提示")
                    .content("货主未开通收款账户，无法报价")
                    .singleBtn(true)
                    .confirm("确定")
                    .contentGravity(Gravity.CENTER)
                    .cancelable(false)
                    .show();
        } else if (!userAccount.isIsDriverOpenFundsAccount() && mGoodsSourceDetail.getTerminal() == 3) {//个人货源资金账户
            new RoundDialog.Builder(this)
                    .title("提示")
                    .content("货主未开通收款账户，无法报价")
                    .singleBtn(true)
                    .confirm("确定")
                    .contentGravity(Gravity.CENTER)
                    .cancelable(false)
                    .show();
        } else {
            if (isTakeOrders) {
                PayBiddingOrderActivity.startForResult(this, mGoodsSourceDetail.getNo(), false, true, "");
            } else {
                CargoQuotationActivity.startForResult(this, mGoodsSourceDetail.getNo(), false, true, "");
            }
        }
    }

    //设置企业信息
    private void setCompanyInfo(GoodsSourceDetail manageItemData) {
        mBinding.headeCompay.callPhonePerson.setVisibility(View.GONE);
        mBinding.headeCompay.companyName.setText(manageItemData.getCompanyName());
        mBinding.headeCompay.businessAddressText.setText(manageItemData.getCompanyAddress());
        mBinding.headeCompay.enterpriseContactName.setText(manageItemData.getConnection());
        mBinding.headeCompay.enterprisePhoneNumber.setText(manageItemData.getConnectionPhone());
        mBinding.headeCompay.rlInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!TextUtils.isEmpty(manageItemData.getCompanyNo())&&manageItemData.getTerminal()!=null&&manageItemData.getTerminal()==1) {
                    WebsiteInfoActivity.start(FreightPrjDetailActivity.this,  mGoodsSourceDetail.getCompanyNo(), WebsiteInfoActivity.WEBSITE_FOR_COMPANY);
                }else if (!TextUtils.isEmpty(manageItemData.getTeamNo())&&manageItemData.getTerminal()!=null&&manageItemData.getTerminal()==2){
                    WebsiteInfoActivity.start(FreightPrjDetailActivity.this,  mGoodsSourceDetail.getTeamNo(), WebsiteInfoActivity.WEBSITE_FOR_TEAM);
                }else{
                    WebsiteInfoActivity.start(FreightPrjDetailActivity.this,  mGoodsSourceDetail.getUserNo(), WebsiteInfoActivity.WEBSITE_FOR_PERSONAL);
                }
            }
        });
        mBinding.headeCompay.enterprisePhoneNumber.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(FreightPrjDetailActivity.this);
                    return;
                }
                flowLog=new LogisticsFlowLog("4","货源联系人","icon");
                showConsignorDialog(manageItemData.getConnectionPhone());
            }
        });
        mBinding.headeCompay.callPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(FreightPrjDetailActivity.this);
                    return;
                }
                flowLog=new LogisticsFlowLog("4","货源联系人","icon");
                showConsignorDialog(manageItemData.getConnectionPhone());
            }
        });
        RequestOptions options = new RequestOptions()
                .dontAnimate()
                .placeholder(manageItemData.getTerminal() != null ? manageItemData.getTerminal() == 3 ? R.drawable.geren_person_touxiang : manageItemData.getTerminal() == 1 ? R.mipmap.goods_list_company_icon : R.drawable.goods_detail_touxiang : R.drawable.goods_detail_touxiang)
                .error(manageItemData.getTerminal() != null ? manageItemData.getTerminal() == 3 ? R.drawable.geren_person_touxiang : manageItemData.getTerminal() == 1 ? R.mipmap.goods_list_company_icon : R.drawable.goods_detail_touxiang : R.drawable.goods_detail_touxiang);
        if (!isDestroyed()) {
            switch (manageItemData.getTerminal()) {
                case 1:
                    mBinding.headeCompay.imgLogo.setOval(false);
                    mBinding.headeCompay.imgLogo.setCornerRadius(4);
                    break;
                case 2:
                    //个人不展示
                case 3:
                    mBinding.headeCompay.imgLogo.setOval(true);
                    break;
            }
            Glide.with(this).load(manageItemData.getLogo()).apply(options).into(mBinding.headeCompay.imgLogo);
        }
        if (manageItemData.getTerminal() == null || manageItemData.getTerminal() == 1) {
            mBinding.headeCompay.role.setBackgroundResource(R.drawable.bg_blue_solid_ring);
            mBinding.headeCompay.role.setTextColor(Color.parseColor("#5792FD"));
            mBinding.headeCompay.role.setText("企业");
            return;
        } else if (manageItemData.getTerminal() == 2) {
            mBinding.headeCompay.role.setText("中介");
            mBinding.headeCompay.role.setTextColor(Color.parseColor("#06C764"));
        } else if (manageItemData.getTerminal() == 3) {
            mBinding.headeCompay.callPhonePerson.setVisibility(View.VISIBLE);
            mBinding.headeCompay.personRole.setVisibility(View.GONE);
            mBinding.headeCompay.companyContacks.setVisibility(View.GONE);
            mBinding.headeCompay.role.setBackgroundResource(R.drawable.bg_orange_ring);
            mBinding.headeCompay.personRole.setText("个人");
            mBinding.headeCompay.personRole.setTextColor(Color.parseColor("#FFC000"));
            mBinding.headeCompay.businessAddress.setText("联系电话：");
            mBinding.headeCompay.businessAddressText.setText(manageItemData.getConnectionPhone());
            mBinding.headeCompay.businessAddressText.setTextColor(Color.parseColor("#5792FD"));
            mBinding.headeCompay.callPhonePerson.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!isLogin()) {
                        VerificationCodeLoginActivity.start(FreightPrjDetailActivity.this);
                        return;
                    }
                    flowLog=new LogisticsFlowLog("4","货源联系人","icon");
                    showConsignorDialog(manageItemData.getConnectionPhone());
                }
            });
            mBinding.headeCompay.businessAddressText.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!isLogin()) {
                        VerificationCodeLoginActivity.start(FreightPrjDetailActivity.this);
                        return;
                    }
                    flowLog=new LogisticsFlowLog("4","货源联系人","icon");
                    showConsignorDialog(manageItemData.getConnectionPhone());
                }
            });
        } else {
            mBinding.headeCompay.role.setVisibility(View.GONE);
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(LogisticsEvent event) {
        if (event.getMessageTag() == EventConstant.EVENT_CARGO_RELEASE_SUCCESS) {
            mBinding.contnetLayout.setVisibility(View.GONE);
            Request();
        } else if (event.getMessageTag() == EventConstant.EVENT_CARINFO_COMMIT) {//接收新增车辆提交事件
            UserOperating.getInstance().refresh();
        } else if (event.getMessageTag() == EventConstant.EVENT_REFRESH_MY_OFFER_PAGE) {
            if ( "ture" .equals(event.getMessageData())){
                finish();
            }else {
                mBinding.contnetLayout.setVisibility(View.GONE);
                Request();
            }
        }
    }

    @Override
    public void onItemClick(GoodsSourcePlace place, String i, int position) {

    }

    @Override
    public void shipperCall(String tel) {

    }

    @Override
    public void receiveCall(String tel) {

    }
}
